@tool
class_name ControllerCommand_AddVel
extends ControllerCommand

## 添加速度

#region 属性
@export var direction:Vector2
@export var vel_property:CompositeProperty
#endregion
#region 字段
#endregion
#region 信号
#endregion

#region 基类方法
#endregion
#region 公共方法
func activate(controller:ControllerComponent,command_dict_by_tag:Dictionary) -> bool:
	if not super(controller,command_dict_by_tag):
		return false
	var vel = Vector2.ZERO
	for commands in command_dict_by_tag.values():
		for command in commands:
			vel += command.get_vel(controller)
	controller.get_entity().change_vel(vel)
	return true
func deactivate(controller:ControllerComponent,command_dict_by_tag:Dictionary):
	var vel = Vector2.ZERO
	for commands in command_dict_by_tag.values():
		for command in commands:
			vel += command.get_vel(controller)
	controller.get_entity().change_vel(vel)
	super(controller,command_dict_by_tag)
func get_vel(controller:ControllerComponent) -> Vector2:
	return direction.normalized() * vel_property.get_value(controller.get_entity())
#endregion
#region 私有方法
#endregion
#region 生命周期函数
func _init() -> void:
	if Engine.is_editor_hint():
		resource_local_to_scene = true
#endregion
